import * as api from './api';
import { dict, UserPageQuery, AddReq, DelReq, EditReq, compute, CreateCrudOptionsProps, CreateCrudOptionsRet } from '@fast-crud/fast-crud';
import { request } from '/@/utils/service';
import { dictionary } from '/@/utils/dictionary';
import { successMessage } from '/@/utils/message';
import {inject} from "vue";
import { auth, auths, authAll } from '/@/utils/authFunction';

export const createCrudOptions = function ({ crudExpose }: CreateCrudOptionsProps): CreateCrudOptionsRet {
	const pageRequest = async (query: UserPageQuery) => {
		return await api.GetList(query);
	};
	const editRequest = async ({ form, row }: EditReq) => {
		form.id = row.id;
		return await api.UpdateObj(form);
	};
	const delRequest = async ({ row }: DelReq) => {
		return await api.DelObj(row.id);
	};
	const addRequest = async ({ form }: AddReq) => {
		return await api.AddObj(form);
	};

	//权限判定
	// const hasPermissions = inject("$hasPermissions")

	return {
		crudOptions: {
			request: {
				pageRequest,
				addRequest,
				editRequest,
				delRequest,
			},
			rowHandle: {
				//固定右侧
				fixed: 'right',
				width: 150,
				buttons: {
					view: {
						show: true,
					},
					edit: {
						iconRight: 'Edit',
						type: 'text',
						show:auth("station_guowangbuliang:Update")
					},
					remove: {
						iconRight: 'Delete',
						type: 'text',
						show:auth("station_guowangbuliang:Delete")
					},
				},
			},
			actionbar:{
				show:auth("station_guowangbuliang:Create")
			},
			form: {
				col: { span: 24 },
				labelWidth: '110px',
				wrapper: {
					is: 'el-dialog',
					width: '600px',
				},
			},
			search:{
				disabled:false,
			},
			columns: {
				$expand:{
					title:'展开图片',
					form:{show:false},
					column:{
						type:'expand',
						align:'center',
						width:'55px',
						columnSetDisabled:true,	//禁止在列设置中选择
					}
				},
				_index: {
					title: '序号',
					form: { show: false },
					column: {
						//type: 'index',
						align: 'center',
						width: '70px',
						columnSetDisabled: true, //禁止在列设置中选择
						//@ts-ignore
						formatter: (context) => {
							//计算序号,你可以自定义计算规则，此处为翻页累加
							let index = context.index ?? 1;
							let pagination: any = crudExpose!.crudBinding.value.pagination;
							return ((pagination.currentPage ?? 1) - 1) * pagination.pageSize + index + 1;
						},
					},
				},
				station:{
					title:'工位编号',
					search:{
						show:true,
						component: {
							props: {
								clearable: true,
							},
							placeholder: '请输入关键词',
						},
					},
					column:{
						sortable:true
					},
				},
				gong_wei_ming_cheng:{
					column:{
						sortable:true
					},
					title:'工位名称',
				},
				wen_ti_fen_lei:{
					column:{
						sortable:true
					},
					title:'问题分类',
					search:{
						show:true,
						component: {
							props: {
								clearable: true,
							},
							placeholder: '请输入关键词',
						},
					},
				},

				PCR_dan_hao:{
					title:'PCR单号',
					search:{
						show:true,
						component: {
							props: {
								clearable: true,
							},
							placeholder: '请输入关键词',
						},
					},
				},
				wen_ti_miao_shu:{
					title:'问题描述',
					search:{
						show:true,
						component: {
							props: {
								clearable: true,
							},
							placeholder: '请输入关键词',
						},
					},
				},
				gen_ben_yuan_yin_fen_xi:{
					title:'根本原因分析',
				},
				duan_qi_jie_jue_cuo_shi:{
					title:'短期解决措施',
				},
				chang_qi_jie_jue_cuo_shi:{
					title:'长期解决措施',
				},
				jin_zhan_ji_hua:{
					title:'进展计划',
				},
				duan_dian_hao:{
					title:'断点号',
				},
				guan_bi_shi_jian:{
					title:'关闭时间',
				},

				bei_zhu:{
					title:'备注',
				},
				update_datetime:{
					title:'更新时间',
					type:'date',
					column:{
						sortable:true
					},
				}
			},
		},
	};
};
